package gsp420.game;

import java.awt.Color;
import java.awt.Graphics;

/**
 * game entity class determine <li>where an entity is in the
 * game
 * 
 * @author Administrator
 * 
 */
public class Entity
{
	/** position */
	protected Point p = new Point();
	/** dimension */
	protected Point d = new Point();
	/** velocity */
	protected Point v = new Point();

	Color c = Color.BLACK;
	
	Entity()
	{
	}

	/**
	 * @param x sets the x position
	 * @param y sets the y position
	 * @param size sets the dimensions (will be this squared)
	 */
	public Entity(int x, int y, int size, Color c)
	{
		p.set(x,y);
		d.set(size,size);
		this.c = c;
	}

	void draw(Graphics g)
	{
		g.setColor(c);
		g.fillRect((int) p.x, (int) p.y, (int) d.x,
				(int) d.y);
	}

	/** @return a reference to the variable storing position */
	Point getPosition()
	{
		return p;
	}

	/**
	 * @return a reference to the variable storing dimensions
	 */
	Point getDimension()
	{
		return d;
	}

	/** @return a reference to the variable storing velocity */
	Point getVelocity()
	{
		return v;
	}

	/**
	 * update process
	 * 
	 * @param ms
	 *            how many milliseconds have passed since
	 *            the last time this process was run
	 *            @return true if something actually changed
	 */
	boolean update(int ms)
	{
		boolean changed = false;
		if(v.x != 0.0 || v.y != 0.0)
		{
			Point howMuchToMoveThisUpdate = new Point(v);
			howMuchToMoveThisUpdate.multiply(ms / 1000.0);
			p.add(howMuchToMoveThisUpdate);
			changed = true;
		}
		return changed;
	}
}
